// Simple simulation

#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdio.h>

using namespace std;

char b[251][251];
bool marked[251][251];
int m, n;

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

bool inside(int x, int y)
{
	return (1 <= x && x <= m && 1 <= y && y <= n);
}

void fill(int x, int y, char color)
{
	for (int i = 0; i < 4; i++) 
	{
		int xx = x+dx[i];
		int yy = y+dy[i];

		if (inside(xx, yy) && (!marked[yy][xx]) && (b[yy][xx] == b[y][x])) 
		{
			marked[yy][xx] = true;
			fill(xx, yy, color);
		}
	}
}

int main()
{
	int x, y, x1, x2, y1, y2;
	char c, color;

	while (cin >> c)
	{
		if (c == 'X') break;

		if (c == 'S')
		{
			string s;
			cin >> s;
			cout << s << endl;
			for (int i = 1; i <= n; i++) 
			{
				for (int j = 1; j <= m; j++) cout << b[i][j];
				cout << endl;
			}			
		}else

		if (c == 'I' || c == 'C') { 
			if (c == 'I') cin >> m >> n;
			for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++) b[i][j] = 'O';		
		}else

		if (c == 'L'){
			cin >> x >> y >> color;
			b[y][x] = color;
		}else

		if (c == 'V'){
			cin >> x >> y1 >> y2 >> color;
			for (int y = min(y1, y2); y <= max(y1, y2); y++) b[y][x] = color;
		}else

		if (c == 'H'){
			cin >> x1 >> x2 >> y >> color;
			for (int x = min(x1, x2); x <= max(x1, x2); x++) b[y][x] = color;
		}else

		if (c == 'K'){
			cin >> x1 >> y1 >> x2 >> y2 >> color;
			for (int x = min(x1, x2); x <= max(x1, x2); x++)
			for (int y = min(y1, y2); y <= max(y1, y2); y++) b[y][x] = color;
		}else

		if (c == 'F') {
			memset(marked, false, sizeof(marked));
			cin >> x >> y >> color;

			marked[y][x] = true;
			fill(x, y, color);

			for (int y = 1; y <= n; y++)
			for (int x = 1; x <= m; x++) 
				if (marked[y][x]) b[y][x] = color;
		}else
		{
			string s;
			getline(cin, s);
		}
	}
	return 0;

}
